//
//  RecommendProductTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/1/24.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "RecommendProductTableViewCell.h"

@implementation RecommendProductTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

- (void)setModel:(Elements *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        
    }
    _backImageView.layer.cornerRadius = 8;
    _backImageView.layer.masksToBounds = YES;
    
    _AlphaView.layer.cornerRadius = 8;
    _AlphaView.layer.masksToBounds = YES;
    
    [self setValues];
    
    
}

/** 赋值 */

- (void)setValues{
    
    NSDictionary *dic = _model.data[0];
    
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:dic[@"cover"]] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    
    _TitleLabel.text = dic[@"title"];
    
    _subTitleLabel.text = [NSString stringWithFormat:@"【 %@ 】", dic[@"sub_title"]];
    
    if ([_model.type integerValue] == 5) {
        _TitleLabel.text = dic[@"cover_title"];
        _subTitleLabel.text =[NSString stringWithFormat:@"【 %@ 】", dic[@"cover_sub_title"]];
        
    }
    
}



- (void)awakeFromNib {
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"yeJianMoShi"] isEqualToString:@"isDay"]) {
        self.backgroundColor = DAYCOLOR;
    }else{
        self.backgroundColor = NIGHTCOLOR;
    }
    
    


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"yeJianMoShi" object:nil];

}

- (void)changeColor:(NSNotification *)notification{
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"yeJianMoShi"]isEqualToString:@"isNight"]) {
        self.backgroundColor = NIGHTCOLOR;
    }else{
        
        self.backgroundColor = DAYCOLOR;
    }
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeColor" object:nil];
    [_backImageView release];
    [_AlphaView release];
    [_TitleLabel release];
    [_subTitleLabel release];
    [super dealloc];
}
@end
